#!/bin/bash
set -eu

TESTDIR=$(readlink -f $(dirname $0))
. $TESTDIR/framework

setupenvironment

buildpackage 'conflicting-package-distupgrade'
buildpackage 'conflicting-package-one'
buildpackage 'conflicting-package-two'
buildpackage 'missing-dependency'
buildpackage 'simple-package-new'
buildpackage 'simple-package-noarch'
buildpackage 'simple-package'
buildpackage 'simple-package-update-conflict'
buildpackage 'simple-package-update' # overwrites the previous built package
buildpackage 'simple-virtual'

generaterepository_and_switch_sources "$TMPWORKINGDIRECTORY/usr/src/RPM/RPMS"

testsuccess aptget update

if [ -n "$APT_TEST_GPGPUBKEY" ]; then
	pkgnames_with_gpgpubkey=('gpg-pubkey' 'gpg\([^)]*@[^)]*\)' 'gpg\([^)]*\)')
else
	pkgnames_with_gpgpubkey=()
fi
readonly -a pkgnames_with_gpgpubkey

testpartsexhaust "${pkgnames_with_gpgpubkey[@]}" \
'conflicting-package-two
no-such-package
simple-virtual
simple-package-noarch
virtual\(dummy\)
simple-package-new
missing-dependency
simple-package
conflicting-package-one' \
-- aptcache pkgnames
